#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
LL a[N];
LL n;
LL k;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		LL sum1 = 0;
		LL sum2 = 0;
		for (int i = 1; i <= n; i++) {
			scanf_s("%lld", &a[i]);
			sum1 += a[i];
			sum2 += 1ll * a[i] * a[i];
		}
		LL sum3 = k - sum2;	
		/*LL temp = (2 * sum1) * (2 * sum1) + (__int128)1ll * 4 * n * sum3;
		LL ans1 = (LL)sqrt(temp);
		ans = ((-2 * sum1) + ans1) / (2 * n);
		cout << "ans==" << " ";*/
		LL l = 0, r = 1e9 + 1;
		while (l + 1 < r) {
			LL mid = (l + r) >> 1;
			/*LL k1 = 1ll * 2 * mid * (sum1);
			LL k2 = 1ll * n * mid * mid;*/
			if ((__int128)mid * (sum1) * 2 + (__int128)n * mid * mid < (__int128)sum3)l = mid;
			else r = mid;
		}
		cout << r / 2 << endl;
	}
	return 0;
}